package com.company.huisuo.repository

import com.company.huisuo.biz.bean.MerchantDanceBean
import com.company.huisuo.biz.bean.MerchantDanceResponse
import com.company.huisuo.network.RetrofitClient
import com.company.huisuo.network.api.MerchantDanceApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 商家舞蹈数据仓库
 */
class MerchantDanceRepository {
    
    private val merchantDanceApi: MerchantDanceApi by lazy {
        RetrofitClient.createService()
    }
    
    /**
     * 获得商家舞蹈列表
     * @param tenantId 租户编号（可选）
     * @param authorization 认证Token（可选）
     */
    suspend fun getMerchantDanceList(
        tenantId: Int? = null,
        authorization: String? = null
    ): Result<List<MerchantDanceBean>> = withContext(Dispatchers.IO) {
        try {
            val response = merchantDanceApi.getMerchantDanceList(tenantId, authorization)
            if (response.code == 0 && response.data != null) {
                Result.success(response.data)
            } else {
                Result.failure(Exception(response.msg ?: "获取商家舞蹈列表失败"))
            }
        } catch (e: Exception) {
            Result.failure(Exception("网络请求失败: ${e.message}"))
        }
    }
}